package com.example.robertluozizhao.framecollectdemo.activity;

import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.example.robertluozizhao.framecollectdemo.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by robert.luozizhao on 2018/3/12.
 */

public class TitleBarActivity extends AppCompatActivity {

    @BindView(R.id.button11)
    Button button11;
    @BindView(R.id.button12)
    Button button12;
    @BindView(R.id.button13)
    Button button13;
    @BindView(R.id.textView)
    TextView textView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_titlebar);
        ButterKnife.bind(this);
    }


    @OnClick({R.id.button11, R.id.button12, R.id.button13})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.button11:
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                textView.setText("  //方式一\n" +
                        "    //getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);\n" +
                        "    //方式二\n" +
                        "    //getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);\n" +
                        "    //方式三 style.xml中配置\n" +
                        "    //<style name=\"fullScreen\" parent=\"Theme.AppCompat.DayNight.NoActionBar\">\n" +
                        "    //        <item name=\"android:windowFullscreen\">true</item>\n" +
                        "    //</style>");
                break;
            case R.id.button12:
                textView.setText("Window window = getWindow();\n" +
                        "                //默认API 最低19\n" +
                        "                if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {\n" +
                        "                    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);\n" +
                        "                    ViewGroup contentView = window.getDecorView().findViewById(Window.ID_ANDROID_CONTENT);\n" +
                        "                    contentView.getChildAt(0).setFitsSystemWindows(false);\n" +
                        "                }");
                Window window = getWindow();
                //默认API 最低19
                if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
                    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                    ViewGroup contentView = window.getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
                    contentView.getChildAt(0).setFitsSystemWindows(false);
                }
                break;
            case R.id.button13:
                textView.setText("       Window window1 = getWindow();\n" +
                        "                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {\n" +
                        "                    window1.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);\n" +
                        "                    window1.setStatusBarColor(getResources().getColor(R.color.status_toolBar_same_color));\n" +
                        "                } else {\n" +
                        "                    // 低于21 处理\n" +
                        "                    window1.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);\n" +
                        "                    ViewGroup systemContent = (ViewGroup) findViewById(android.R.id.content);\n" +
                        "                    View statusBarView = new View(this);\n" +
                        "                    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(this));\n" +
                        "                    statusBarView.setBackgroundColor(getResources().getColor(R.color.status_toolBar_same_color));\n" +
                        "                    systemContent.getChildAt(0).setFitsSystemWindows(true);\n" +
                        "                    systemContent.addView(statusBarView, 0, lp);\n" +
                        "                }");
                Window window1 = getWindow();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    window1.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                    window1.setStatusBarColor(getResources().getColor(R.color.status_toolBar_same_color));
                } else {
                    // 低于21 处理
                    window1.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                    ViewGroup systemContent = (ViewGroup) findViewById(android.R.id.content);
                    View statusBarView = new View(this);
                    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(this));
                    statusBarView.setBackgroundColor(getResources().getColor(R.color.status_toolBar_same_color));
                    systemContent.getChildAt(0).setFitsSystemWindows(true);
                    systemContent.addView(statusBarView, 0, lp);
                }
                break;
        }
    }


    /*  * 获取状态栏高度
     * @param context
     * @return
             */
    public static int getStatusBarHeight(Context context) {
        int result = 0;
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen",
                "android");
        if (resourceId > 0) {
            result = context.getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }
}
